<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org/">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
    <script th:src="@{/static/jquery-2.1.4.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/mylayer.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/kindeditor/kindeditor.js}" type="text/javascript" charset="utf-8"></script>
</head>
<body>
    <form class="layui-form" lay-filter="updateFormFilter" action="">
        <input type="hidden" name="id">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">邮箱</label>
            <div class="layui-input-block">
                <input type="text" name="email" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">手机号</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit lay-filter="submit">修改</button>
                <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
            </div>
        </div>
    </form>


<script>
    layui.use(['form'],function (){
        var form = layui.form;

        //拿到studentcou_list.jsp传递过来的参数--编辑回显数据
        var queryString = window.location.search;
        var urlParams = new URLSearchParams(queryString);
        var id = urlParams.get("id");

        $.post(
            '/admin/selectById',
            {'id':id},
            function (result) {
                //console.log(result);
                if (result.code == 0){
                    form.val('updateFormFilter',result.data);
                }
            },
            'json'
        );


         //绑定提交事件
         form.on('submit(submit)',function (data) {
             //获取表单字段
             var field = data.field;
             console.log(data);
             // 此处可执行 Ajax 等操作
             $.post(
                 '/admin/updateAdmin',
                 field,
                 function (result) {
                     console.log(result);
                     if (result.code == 0) {
                         mylayer.okMsg(result.msg);
                         //layer.close(index);
                         //table.reload('tableId');
                         setInterval(function (){
                             //关闭弹出框
                             var index = parent.layer.getFrameIndex(window.name);
                             parent.layer.close(index);
                             //刷新父页面
                             window.parent.location.reload();
                         },2000)
                     } else {
                         mylayer.errorMsg(result.msg);
                     }
                 },
                 'json'
             );
             return false;//阻止默认form跳转
         });
    });
</script>
</body>
</html>